<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue指令</title>
    <script type="text/javascript" src="js/vue.js"></script>
    <style>
        .ok{
            color:green;
        }
        .error{
            color:red;
        }
    </style>
</head>
<body>
<div id="d1">
    <!--<img v-bind:src="url" alt="图片加载失败"/>-->
    <!--
        v-bind:属性可以简写为:属性
        即:v-bind可以省略
    -->
    <img :src="url" alt="图片加载失败" :width="width"/><br/>
    <!--
        样式选择
        {样式1:布尔值1,样式2:布尔值2}
        当对应的某一个布尔值为true时,使用与之对应的样式
        此时的布尔值1与布尔值2是对立的
        假设布尔值1为true,此时的属性值即为样式1
        假设布尔值2为true,此时的属性值即为样式2
    -->
    用户名:<input type="text" v-model="username" :class="{ok:flag,error:!flag}" @input="checkUsername($event.target.value)"/><br/>
    密码:<input type="password" v-model="password"/><br/>
    性别:
    <input type="radio" v-model="gender" value="man"/>男
    <input type="radio" v-model="gender" value="woman"/>女<br/>
    学历:
    <select v-model="edu">
        <option value="-1">请选择</option>
        <option value="1">大专</option>
        <option value="2">本科</option>
        <option value="3">研究生</option>
    </select><br/>
    兴趣:
    <input type="checkbox" value="eat" v-model="hobbies"/>吃饭
    <input type="checkbox" value="sleep" v-model="hobbies"/>睡觉
    <input type="checkbox" value="study" v-model="hobbies"/>学Java<br/>

</div>
</body>
<script>
    new Vue({
        el: "#d1",
        data:{
            url: "https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fup.enterdesk.com%2Fphoto%2F2012-3-2%2Fenterdesk.com-B526ECADD33DBD367676A93E051BA1EC.jpg&refer=http%3A%2F%2Fup.enterdesk.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1662874803&t=6908f57cbb01afa7ba42c77cfb456462",
            width: "300px",
            username: "admin",
            password: "123456",
            gender: "woman",
            edu: "1",
            hobbies: ["sleep"],
            flag: true
        },methods:{
            checkUsername(username){
                this.flag = username.length >= 6 && username.length <= 12;
            }
        }
    })
</script>
</html>